<?php

$taskId = (int) $_REQUEST['taskId'];
if (empty($taskId)) {
    error_obj::setError(new error_obj('empty taskID', __FILE__, ''), UNEXCEPTED);
    return false;
}

$task_obj = new task_obj();
$client_obj = new client_obj();
$user_obj = new user_obj();
$task_phorum_obj = new task_phorum_obj();

$task_data = $task_obj->getTaskById($taskId);

if (error_obj::isError($task_data)) {
    error_obj::setError($task_data, UNEXCEPTED);
} elseif (empty($task_data)) {
    error_obj::setError(new error_obj('empty task data', __FILE__, ''), UNEXCEPTED);
} else {
    $filter = array(
        'client' => $task_data['client'],
        'userlevel' => USER_TYPE_CLIENT
    );
    $GLOBALS['template_data']['prefill']['date'] = date('d.m.Y');
    if ($task_data['deadline'] != MAX_DEADLINE_DB)
        $GLOBALS['template_data']['prefill']['return_date'] = base_obj::convertDateTo($task_data['deadline'], 'dd.mm.yyyy', 'date');
    $GLOBALS['template_data']['users'] = $user_obj->getUsers("users_id, surname, name", $filter);
    $GLOBALS['template_data']['client_info'] = $client_obj->getClient($task_data['client']);
    if (!empty($GLOBALS['template_data']['client_info']['contactPerson']))
        $GLOBALS['template_data']['contact_info'] = $user_obj->getUserById ($GLOBALS['template_data']['client_info']['contactPerson']);
    if (!empty($_REQUEST['selectedUser']))
        $GLOBALS['template_data']['user_info'] = $user_obj->getUserById($_REQUEST['selectedUser']);
    $GLOBALS['template_data']['descriptions'] = $task_phorum_obj->getPostsInPhorum(array("task_id" => $taskId), 'task_phorum_id ASC');
    foreach ($GLOBALS['template_data']['descriptions'] as $key => $value) {
        $GLOBALS['template_data']['descriptions'][$key]['text'] = htmlspecialchars_decode($value['text']);   
    }
    $GLOBALS['template_data']['task'] = $task_data;
}
?>
